<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
            //类的构造函数里定义的function，即为私有方法；
            //而在构造函数里用var声明的变量，也相当于是私有变量。
            var Person = function(name,sex){
                this.name = name;
                this.sex = sex;
                var _privateVariable = "";//私有变量
                //构造器中定义的方法，即为私有方法
                function privateMethod(){
                    _privateVariable = "private value";
                    alert("私有方法被调用！私有成员值：" + _privateVariable);
                }
                privateMethod(); //构造器内部可以调用私有方法
            }

            Person.prototype.sayHello = function(){
                alert("姓名：" + this.name + "，性别：" + this.sex);
            }

            var p = new Person("王帅","男");
            p.sayHello();
            p.privateMethod();//这里将报错，私成方法无法被实例调用
            alert(p._privateVariable);//显示: undefined
        </script>
    </head>
    <body>
        TODO write content
    </body>
</html>
